//
//  HTInterstitialAdView.swift
//  MagaCore
//
//  Created by MrMessy on 2023/5/20.
//

import SwiftUI

struct HTMRECAdView: View {
    var var_showClose: Bool = true
    var var_onDisappear: (() -> Void)?
    var var_onPushPremium: (() -> Void)?

    @State private var var_showPremiumGuide: Bool = false

    var body: some View {
        ZStack {
            if var_showPremiumGuide {
                LazyVStack(spacing: 50) {
                    Button {
                        if var_onPushPremium != nil {
                            var_onPushPremium!()
                        } else {
                            NotificationCenter.default.post(name: HTConfig.STATIC_notification_changeTabbar, object: nil,userInfo: ["currentIndex": 3])
                            var_onDisappear!()
                        }
                    } label: {
                        Text("Get Premium to remove ads")
                            .foregroundColor(Color(hex: "#EDC391"))
                            .font(.system(size: UIDevice.ht_fixToWidth(width: 16)))
                            .frame(width: UIDevice.ht_fixToWidth(width: 250), height: UIDevice.ht_fixToWidth(width: 46))
                            .background(Color.black)
                    }

                    Button {
                        var_onDisappear!()
                    } label: {
                        Text("Cancel")
                            .foregroundColor(Color.white)
                            .font(.system(size: UIDevice.ht_fixToWidth(width: 16)))
                            .frame(width: UIDevice.ht_fixToWidth(width: 250), height: UIDevice.ht_fixToWidth(width: 46))
                            .background(Color.black)
                    }
                }
                .frame(width: UIDevice.ht_fixToWidth(width: 300), height: UIDevice.ht_fixToWidth(width: 250))
            } else {
                ZStack(alignment: .topTrailing) {
                    HTMRECAd()
                        .frame(width: UIDevice.ht_fixToWidth(width: 300), height: UIDevice.ht_fixToWidth(width: 250))
                    Button {
                        var_showPremiumGuide.toggle()
                    } label: {
                        Image("ad_close_black")
                            .frame(width: UIDevice.ht_fixToWidth(width: 24), height: UIDevice.ht_fixToWidth(width: 24))
                    }
                    .frame(width: UIDevice.ht_fixToWidth(width: 30), height: UIDevice.ht_fixToWidth(width: 30))
                }
                .frame(alignment: .topTrailing)
            }
        }
        .background(Color(hex: "#D9D9D9"))
        .frame(width: UIDevice.ht_fixToWidth(width: 300), height: UIDevice.ht_fixToWidth(width: 250))
    }
}
